import 'package:bluetooth_helper/models/MyHomePageData.dart';
import 'package:bluetooth_helper/pages/BluetoothPage.dart';
import 'package:bluetooth_helper/pages/CommandPage.dart';
import 'package:bluetooth_helper/pages/SettingPage.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_blue_plus/flutter_blue_plus.dart';

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  final _MyHomePageData = MyHomePageData();

  final List<Tab> myTabs = <Tab>[
    Tab(icon: Icon(Icons.bluetooth),),
    Tab(icon: Icon(Icons.terminal)),
    Tab(icon: Icon(Icons.settings)),
  ];



  void setStateEvent(Function action){
    setState(() {
      action();
      // showMsg("清空蓝牙列表！");
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        // Center is a layout widget. It takes a single child and positions it
        // in the middle of the parent.
        child: DefaultTabController(
          length: myTabs.length,
          child: Scaffold(
            appBar: AppBar(
              title: TabBar(
                tabs: myTabs,
              ),
            ),
            body: TabBarView(children: [
              BluetoothPage(_MyHomePageData,this.setStateEvent),
              CommandPage(),
              SettingPage(),
            ]),
          ),
        ),
      ),
    );
  }
}

